﻿using MaterialDesignThemes.Wpf;

using PLCS.App.Shared.Events;
using PLCS.App.Shared.Models;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PLCS.App.Shared.ViewModels.UserControls.Chlidren
{
    public class EditTrackControlDialogViewModel : HostDialogViewModel
    {
        private ModelControl _model;
        private readonly IEventAggregator _eventAggregator;

        public EditTrackControlDialogViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
        }

        public ModelControl Model
        {
            get { return _model; }
            set { SetProperty(ref _model, value); }
        }

        protected override void Save()
        {
            _eventAggregator.GetEvent<ModelControlEvent>().Publish(Model);
            DialogHost.Close(IdentifierName, new DialogResult(ButtonResult.OK));
        }

        public override void OnDialogOpened(IDialogParameters parameters)
        {
            var value = parameters.GetValue<ModelControl>("model");
            value ??= new ModelControl();
            value.ControlType = "Track";
            Model = value;
        }
    }
}